<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    	<link rel="icon" type="image/png" href="img/favicon.png" sizes="16x16">
		<title>阿噹共享汽车-地勤车况系统</title>
		<link rel="stylesheet" href="libs/wuui/weui.min.css" />
		<style type="text/css">
		.page.pg-top{
			padding-top: 50px;
		}
		.page.pg-bottom{
			padding-bottom: 50px;
		}
		.page,body {
			background-color: #f8f8f8;
		}
		header {
			width: 100%;
			height: 50px;
			background: #01ace9;
			position: fixed;
			top: 0;
			z-index: 3;
		}
		header .back:before {
			content: " ";
			display: inline-block;
			height: 10px;
			width: 10px;
			border-width: 0 0 2px 2px;
			border-color: #fff;
			border-style: solid;
			-webkit-transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
			transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
		}
		
		header a.placeholder {
			display: block;
			padding: 0 20px
		}
		
		header .placeholder {
			margin: 0;
			height: 50px;
			line-height: 50px;
			background: none;
			font-size: 16px;
			color: #fff;
		}
		.weui-cells{
			font-size:14px;
		}
		.prefile .weui-cells{
			margin-top: 0;
		}
		.password{
			padding: 20px;;
		}
		.password .weui-cell {
			border: 1px solid #e5e5e5;
			border-radius: 4px;
		}
		
		.password .weui-btn-area {
			margin: 1.17647059em 0 0.5em;
		}
		#loginBtn{
			background: #d4f2fd;
			font-size:16px;
			color:#333;
		}
		#loginBtn:active
		{
			background:#d4f2fd;
		}
		</style>
	</head>

	<body ontouchstart>
		
		<header>
			<div class="weui-flex">
				<div>
					<a href="javascript:history.go(-1);" class="placeholder back"> 返回 </a>
				</div>
			</div>
		</header>
		
		<div class="page pg-top pg-bottom password">
			<div class="weui-cells weui-cells_form">
				<div class="weui-cell">
					<div class="weui-cell__hd">
	                    <label class="weui-label">原密码</label>
	                </div>
					<div class="weui-cell__bd">
						<input class="weui-input" type="password" name="oldPassword" placeholder="原密码" />
					</div>
				</div>
			</div>
			<div class="weui-cells weui-cells_form">
				<div class="weui-cell">
					<div class="weui-cell__hd">
	                    <label class="weui-label">新密码</label>
	                </div>
					<div class="weui-cell__bd">
						<input class="weui-input" type="password" name="newPassword" placeholder="新密码" />
					</div>
				</div>
			</div>
			<div class="weui-cells weui-cells_form">
				<div class="weui-cell">
					<div class="weui-cell__hd">
	                    <label class="weui-label">确认密码</label>
	                </div>
					<div class="weui-cell__bd">
						<input class="weui-input" type="password" name="newPassword2" placeholder="确认密码" />
					</div>
				</div>
			</div>
			<div class="weui-btn-area">
				<a id="loginBtn" href="javascript:;" class="weui-btn weui-btn_primary">修改密码</a>
			</div>
		</div>
		
		<script type="text/javascript" src="libs/jquery-2.2.3.min.js" charset="UTF-8"></script>
		<!--weui.js需要在body里面加载才起作用-->
		<script type="text/javascript" src="libs/weui.js/weui.min.js" charset="UTF-8"></script>
		<script type="text/javascript" src="js/app.js" charset="UTF-8"></script>
		<script type="text/javascript">
		$(function(){
			var $loginBtn = $('#loginBtn'),
				user = app.getJSONSessionStorage('user'),
				uploadLoading = null;
			
			$loginBtn.on('click', function(){
				var oldPassword = $('input[name=oldPassword]').val(),
					newPassword = $('input[name=newPassword]').val()
					newPassword2 = $('input[name=newPassword2]').val()
				if(null == oldPassword || '' === oldPassword.trim()) {
					weui.alert('原密码不能为空'); return ;
				}
				if(null == newPassword || '' === newPassword.trim()) {
					weui.alert('新密码不能为空'); return ;
				}
				if(null == newPassword2 || '' === newPassword2.trim()) {
					weui.alert('确认密码不能为空'); return ;
				}
				if(newPassword != newPassword2) {
					weui.alert('新密码与确认密码不一致'); return ;
				}
				
				uploadLoading = weui.loading('提交数据中');
				$.ajax({
	    			url:"/api/tukuan/mobile/car/user/updatePassword",
					type:"post",
					data: {
						carUserId: user.id,
						mobile: user.mobile,
						oldPassword: oldPassword,
						newPassword: newPassword
					},
					success: function(result){
						uploadLoading.hide() ;
						if(result.status) {
				    		window.location.href = 'msg.html?status=1&backUrl=login.html&backTitle='+encodeURI('重新登陆')+'&message='+encodeURI('密码修改成功，请重新登陆')  ;
				       	} else {
				       		window.location.href = 'msg.html?status=2&backTitle='+encodeURI('返回修改密码')+'&message='+encodeURI(result.message)  ;
				       	}
					},
					error: function(){
						uploadLoading.hide() ;
					}
				});
			});
			
		});
		</script>
	</body>

</html>